package link.anyauto.provider;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.hardware.camera2.params.StreamConfigurationMap;
import android.os.StrictMode;

/**
 * Created by Administrator on 2016/5/5.
 */
public class UserInfoDbHelper extends SQLiteOpenHelper {

    public UserInfoDbHelper(Context ctx) {
        super(ctx, DB_NAME, null, DB_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        delete(sqLiteDatabase);
        sqLiteDatabase.execSQL(POST_SQL);
        sqLiteDatabase.execSQL(COMPANY_SQL);
    }

    void delete(SQLiteDatabase db) {
        db.execSQL(POST_DROP);
        db.execSQL(COMPANY_DROP);
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
        delete(sqLiteDatabase);
        onCreate(sqLiteDatabase);
    }

    public static final String DB_NAME = "userinfo.db";
    public static final int DB_VERSION = 1;
    public static final String TABLE_USER_INFO = "userinfo";
    public static final String TABLE_COMPANY = "company";

    public static final String TEL = "tel_num";
    public static final String DESC = "desc";
    public static final String COMP_ID = "comp_id";
    public static final String ID = "id";
    public static final String BUSINESS = "business";
    public static final String ADDR = "addr";

    static final String POST_SQL = "create table " + TABLE_USER_INFO + "(" + TEL + " text, " + COMP_ID + " text, "
            + DESC + " text)";
    static final String COMPANY_SQL = "create table " + TABLE_COMPANY + "(" + ID + " text primary key, " + BUSINESS + " text, " + ADDR + " text)";

    static final String POST_DROP = "drop table if exists " + TABLE_USER_INFO;
    static final String COMPANY_DROP = "drop table if exists " + TABLE_COMPANY;
}
